package com.firesrc.service.server;

import java.sql.ResultSet;
import java.util.List;

import jodd.bean.BeanTool;

import com.firesrc.bean.FullKeyword;
import com.firesrc.bean.Keyword;
import com.firesrc.bean.ProcessorBean;
import com.firesrc.service.FullKeywordService;
import com.firesrc.service.impl.FullKeywordServiceImpl;
import com.firesrc.util.GenerateSequenceUtil;
import com.firesrc.util.RstToListUitl;
import com.firesrc.util.SqlTsvTool;

public class ImportKeywordCommand implements ProcessDataCommand {

  @Override
  public String process(ProcessorBean processorBean) {
    ResultSet rst = SqlTsvTool.getRstFromProcessorBean(processorBean);
    List<Keyword> importList = RstToListUitl.getKeywordListFromRst(rst);
    FullKeywordService service = new FullKeywordServiceImpl();
    FullKeyword fullKeyword = null;
    for (Keyword keyword : importList) {
      fullKeyword = new FullKeyword();
      BeanTool.copy(keyword, fullKeyword);
      fullKeyword.setId(GenerateSequenceUtil.generateSequenceNo());
      fullKeyword.setSrcId(keyword.getId());
      service.add(fullKeyword);
    }
    return "ok";
  }

}
